using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using HengTong.Model._Admin;
using HengTong.Model.Db.SupplyChain.Material;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Attributes;

namespace HengTong.Model.Db.SupplyChain.Purchase;

/// <summary>
/// 采购需求池主表
/// </summary>
/// <remarks>
/// 用于汇总和管理已审批通过的采购申请单需求，支持采购专员统一规划和执行采购任务
/// </remarks>
[Display(Name = "采购需求池", Description = "汇总和管理已审批通过的采购申请单需求", GroupName = "供应链")]
public class SysPurchaseRequirementPool : BasePoco
{
    #region 基本信息
    
    /// <summary>
    /// 需求池名称
    /// </summary>
    [StringLength(64)]
    [Required(ErrorMessage = "需求池名称不能为空")]
    [Display(Name = "需求池名称", Description = "需求池的名称", GroupName = "基本信息")]
    public string Name { get; set; }
    
    /// <summary>
    /// 获取或设置需求池编号
    /// </summary>
    /// <value>需求池的唯一编号</value>
    [Required(ErrorMessage = "需求池编号不能为空")]
    [Display(Name = "需求池编号", Description = "需求池的唯一编号", GroupName = "基本信息")]
    [StringLength(64)]
    public string Code { get; set; }
    
    #endregion

    #region 汇总信息
    /// <summary>
    /// 获取或设置总需求金额
    /// </summary>
    /// <value>需求池内所有物料需求的总金额</value>
    [Required(ErrorMessage = "总需求金额不能为空")]
    [Display(Name = "总需求金额", Description = "需求池内所有物料需求的总金额", GroupName = "汇总信息")]
    [Column(TypeName = "decimal(18,2)")]
    public decimal TotalAmount { get; set; }

    /// <summary>
    /// 获取或设置紧急需求数量
    /// </summary>
    /// <value>标记为紧急的需求数量</value>
    [Required(ErrorMessage = "紧急需求数量不能为空")]
    [Display(Name = "紧急需求数量", Description = "标记为紧急的需求数量", GroupName = "汇总信息")]
    public int UrgentCount { get; set; }

    #endregion

    #region 状态信息

    /// <summary>
    /// 获取或设置需求池状态
    /// </summary>
    /// <value>需求池的状态</value>
    [Required(ErrorMessage = "需求池状态不能为空")]
    [Display(Name = "需求池状态", Description = "需求池的状态", GroupName = "状态信息")]
    public CommonState? State { get; set; }
    
    /// <summary>
    /// 获取或设置是否为默认需求池
    /// </summary>
    [Display(Name = "是否默认需求池", Description = "标记该需求池是否为默认需求池", GroupName = "状态信息")]
    public bool IsDefault { get; set; }
    
    #endregion

    #region 责任人信息

    /// <summary>
    /// 获取或设置采购负责人
    /// </summary>
    /// <value>负责该需求池的采购专员</value>
    [Display(Name = "采购负责人", Description = "负责该需求池的采购专员", GroupName = "责任人信息")]
    public FrameworkUser PurchaserInCharge { get; set; }

    /// <summary>
    /// 获取或设置采购负责人ID
    /// </summary>
    /// <value>负责该需求池的采购专员ID</value>
    [Display(Name = "采购负责人ID", Description = "负责该需求池的采购专员ID", GroupName = "责任人信息")]
    public Guid? PurchaserInChargeId { get; set; }
    
    #endregion

    #region 备注信息

    /// <summary>
    /// 获取或设置备注
    /// </summary>
    /// <value>需求池的备注说明</value>
    [Display(Name = "备注", Description = "需求池的备注说明", GroupName = "备注信息")]
    [StringLength(512)]
    public string Remark { get; set; }

    #endregion

    #region 关联信息

    /// <summary>
    /// 获取或设置需求池明细列表
    /// </summary>
    /// <value>需求池包含的所有需求明细</value>
    [Display(Name = "需求池明细", Description = "需求池包含的所有需求明细", GroupName = "关联信息")]
    public List<SysPurchaseRequirementPoolEntry> Items { get; set; }
    
    /// <summary>
    /// 获取或设置需求池物料分类列表
    /// </summary>
    [Display(Name = "需求池物料分类", Description = "需求池关联的物料分类列表", GroupName = "关联信息")]
    public List<SysPurchaseRequirementPoolMaterialGroup> MaterialGroups { get; set; }
    
    /// <summary>
    /// 采购需求池管理人员关联表
    /// </summary>
    [Display(Name = "采购需求池管理人员关联表")]
    public List<SysPurchaseRequirementPoolManager> Managers { get; set; }
    
    #endregion
}

/// <summary>
/// 采购需求池物料分类关联表
/// </summary>
[MiddleTable]
public class SysPurchaseRequirementPoolMaterialGroup : TopBasePoco
{
    [Display(Name = "需求池", Description = "关联的采购需求池")]
    public Guid? PurchaseRequirementPoolId { get; set; }
    public SysPurchaseRequirementPool PurchaseRequirementPool { get; set; }

    [Display(Name = "物料分类", Description = "关联的物料分类")]
    public Guid? GroupId { get; set; }
    public SysMaterialGroup Group { get; set; }
}

/// <summary>
/// 采购需求池管理人员关联表
/// </summary>
[MiddleTable]
public class SysPurchaseRequirementPoolManager : TopBasePoco
{
    [Display(Name = "需求池", Description = "关联的采购需求池")]
    public Guid? PurchaseRequirementPoolId { get; set; }
    public SysPurchaseRequirementPool PurchaseRequirementPool { get; set; }

    [Display(Name = "管理人员", Description = "关联的管理人员")]
    public Guid? ManagerId { get; set; }
    public FrameworkUser Manager { get; set; }
}